package com.alquiler.managers;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class SimpleEntityManager {
	
	 private  EntityManager entityManager;
     private  EntityManagerFactory factory;
     
     private static SimpleEntityManager instance = new SimpleEntityManager();
   
     
     private SimpleEntityManager(){
    	 this.factory = Persistence.createEntityManagerFactory("tarifaFutbol");
         this.entityManager = factory.createEntityManager();
     }
     
     public static SimpleEntityManager getInstance(){    	 
    	 return instance;
     }
     
     
     public void beginTransaction(){
         entityManager.getTransaction().begin();
     }
      
     public void commit(){
         entityManager.getTransaction().commit();
     }
     
     /**
      * 
      */
     public void close(){
         entityManager.close();
         factory.close();
     }
      
     public void rollBack(){
         entityManager.getTransaction().rollback();
     }
      
     public EntityManager getEntityManager(){
         return entityManager;
     }  

}
